import java.util.ArrayList;
import java.util.HashMap;
import edu.uci.ics.jung.graph.UndirectedGraph;

public class AddEdge {	
	public int TOTAL_EDGE_NUM;
	public int ADDED_EDGE_NUM;
	public AddEdge(){
		this.TOTAL_EDGE_NUM = 0;
		this.ADDED_EDGE_NUM = 0;
	}
	
	public UndirectedGraph addFirstParent(UndirectedGraph x, HashMap<Integer, ArrayList<MyNode>> nodelist, MyNode bornNode){		
		MyNode parentNode = null;
		int rndAge = (int) ((Math.random()*19)+20);
		float rnd = (float)Math.random();
		int pickNodeNum = 0; /* record the people amount in specified age */
		
		for(int j=0; j<2; j++){ 
			rnd = (int) Math.random();
			rndAge = (int) ((Math.random()*19)+20);
			
			while(!nodelist.containsKey(rndAge)){
				System.out.print("選的年齡"+rndAge +"沒人啦" );
				rndAge = (int) ((Math.random()*19)+20);
				System.out.println(" 重新選" + rndAge+"歲的人");
			}
			/* pick a random index node from specified age */
			pickNodeNum = (int) ((nodelist.get(rndAge).size()-1)*rnd);
			/*  add edge different from before*/
			while( parentNode == nodelist.get(rndAge).get(pickNodeNum) ){
				rnd = (int) Math.random(); 
				rndAge = (int) ((Math.random()*19)+20);
				while(!nodelist.containsKey(rndAge))
					rndAge = (int) ((Math.random()*19)+20);
				pickNodeNum = (int) ( (nodelist.get(rndAge).size()-1)*rnd);
			}
			x.addEdge( (ADDED_EDGE_NUM++)+"", bornNode, parentNode = (nodelist.get(rndAge).get( (int) (pickNodeNum) )) );			
			TOTAL_EDGE_NUM++;
		}
		return x;
	}
	public void addSpouse(){
		
	}
	public void addSibling(){
		
	}
	
	
}
